package com.atguigu.tingshu.payment.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.payment.service.PaymentInfoService;
import com.atguigu.tingshu.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;


    @Autowired
    private PaymentInfoService paymentInfoService;


    /**
     * 对接微信支付
     *
     * @param paymentType
     * @param orderNo
     * @return
     */
    @PostMapping("/wxPay/createJsapi/{paymentType}/{orderNo}")
    public Result<Map<String, String>> createJsapi(@PathVariable String paymentType, @PathVariable String orderNo) {

        log.info("开始调用微信支付接口");
        Map<String, String> result = wxPayService.createJsapi(paymentType, orderNo);
        log.info("调用微信支付接口结束");
        return Result.ok(result);
    }

    @GetMapping("/wxPay/queryPayStatus/{orderNo}")
    public Result<Boolean> queryPayStatus(@PathVariable String orderNo) {
        Boolean b = wxPayService.queryPayStatus(orderNo);
        return Result.ok(b);
    }

    @PostMapping("/wxPay/notify")
    public Map<String, String> paymentSuccessNotify(HttpServletRequest request) {
        log.info("微信支付回调");
        return wxPayService.paymentSuccessNotify(request);
    }
}
